package com.hc.category3;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
 * @author hecai
 * @date 2021/12/9 23:51
 */
public class DB {
    /**
     * 初始化数据
     *
     * @return
     */
    public static List<Category> init() {
        Random random = new Random();

        List<Category> categoryList = new ArrayList<>();
        categoryList.add(new Category(1, "aa", null, random.nextInt(20), new ArrayList<>()));
        categoryList.add(new Category(2, "bb", null, random.nextInt(20), new ArrayList<>()));

        categoryList.add(new Category(3, "aa1", 1, random.nextInt(20), new ArrayList<>()));
        categoryList.add(new Category(4, "aa2", 1, random.nextInt(20), new ArrayList<>()));

        categoryList.add(new Category(5, "bb1", 2, random.nextInt(20), new ArrayList<>()));
        categoryList.add(new Category(6, "bb2", 2, random.nextInt(20), new ArrayList<>()));

        categoryList.add(new Category(7, "aa11", 3, random.nextInt(20), new ArrayList<>()));
        categoryList.add(new Category(8, "aa12", 3, random.nextInt(20), new ArrayList<>()));
        categoryList.add(new Category(9, "aa13", 4, random.nextInt(20), new ArrayList<>()));
        categoryList.add(new Category(10, "aa14", 4, random.nextInt(20), new ArrayList<>()));

        categoryList.add(new Category(11, "bb15", 5, random.nextInt(20), new ArrayList<>()));
        categoryList.add(new Category(12, "bb16", 5, random.nextInt(20), new ArrayList<>()));
        categoryList.add(new Category(13, "bb17", 6, random.nextInt(20), new ArrayList<>()));
        categoryList.add(new Category(14, "bb18", 6, random.nextInt(20), new ArrayList<>()));
        return categoryList;
    }

    public static void main(String[] args) {
        List<Category> list = init();
        Collections.sort(list, (item1, item2) -> item1.getSort() - item2.getSort());
        // Collections.sort(list, Comparator.comparingInt(Category::getSort));
        list.forEach(System.out::println);
    }
}
